<template>
	<view>
		<navbar title="考勤签到" :isbg="false" :autoBack="true" :opacity='1'>
			
		</navbar>
		<view class="con">
			<view class="box">
				<view class="box__btn" @click="clickdk">
					{{text}}
					<image src="/static/data/sz.png" class="box__btn__icon" mode=""></image>
				</view>
				<view class="box__addr">
					{{form.address}}
				</view>
				<image :class="issx?'spin-element':''" src="/static/data/sx.png" @click="getaddr" class="box__sx" mode=""></image>
			</view>
			<view class="box1">
				<view class="box1__item" v-for="(item,index) in list" :key="index">
					<view class="box1__item__name">
						{{item.address}}
					</view>
					<view class="box1__item__time">
						{{$u.timeFormat(item.createtime, 'yyyy-mm-dd hh:MM:ss')}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import datagl from '@/api/_datagl.js'
	export default {
		data() {
			return {
				text:'一键打卡',
				form:{
					address:""
				},
				issx:false,
				list:[],
				key:'7HFBZ-Q7PCL-Q7FPK-MNB5G-HDYQ7-ZHFZJ'
			};
		},
		methods:{
			async clickdk(){
				if(this.text=='已打卡'){
					return
				}
				let res= await datagl.createCheck({address:this.form.address})
				if(res.data.code==1){
					this.text='已打卡'
					this.getlist()
				}
			},
			getaddr(){
				let _this=this
				_this.issx=true
				uni.showLoading({
					title:'正在获取地址'
				})
				uni.getLocation({
					geocode:true,
					type: 'gcj02',
					success: function (res) {
						uni.request({
							url:`https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=${_this.key}`,
							success(r) {
								console.log(r)
								_this.form.address=r.data.result.formatted_addresses.standard_address
								_this.issx=false
								uni.hideLoading()
							}
						})
					},
					fail(r) {
						_this.issx=false
						uni.hideLoading()
					},
					complete() {
						_this.issx=false
						uni.hideLoading()
					}
				});
			},
			async getlist(){
				let res = await datagl.getCheckList()
				if (res.data.code==1) {
					this.list=res.data.data
				}
			}
		},
		onLoad() {
			this.getlist()
			this.getaddr()
			
		}
	}
</script>

<style lang="scss">
page{
	background-color: #F8F8F8;
}
.con{
	padding: 30rpx;
	.box{
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 34rpx;
		&__btn{
			margin-top: 100rpx;
			width: 260rpx;
			height: 260rpx;
			background: #2A51FA;
			border: 20rpx solid #e1e6fe;
			position: relative;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-family: AlimamaShuHeiTi, AlimamaShuHeiTi;
			font-weight: bold;
			font-size: 48rpx;
			color: #FFFFFF;
			margin-bottom: 77rpx;
			&__icon{
				width: 165rpx;
				height: 125rpx;
				position: absolute;
				bottom: -55rpx;
				right: -34rpx;
			}
		}
		&__addr{
			width: 450rpx;
			font-family: PingFang-SC, PingFang-SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #1E1E1E;
			line-height: 40rpx;
			text-align: center;
			margin-bottom: 40rpx;
		}
		&__sx{
			width: 49rpx;
			height: 49rpx;
			margin-bottom: 59rpx;
		}
	}
	.box1{
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 8rpx 0 0 36rpx;
		&__item{
			padding: 38rpx 0 36rpx;
			border-bottom: 2rpx solid #F9F9F9;
			&__name{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #010101;
				line-height: 30rpx;
			}
			&__time{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #6D6D6D;
				line-height: 24rpx;
				margin-top: 29rpx;
			}
		}
	}
}
</style>
